package grame;

import org.hibernate.cfg.ImprovedNamingStrategy;
import org.hibernate.internal.util.StringHelper;

/**
 * @author "Shining Wang<shiningwang@topca.com>"
 */
public class GrameNamingStrategy extends ImprovedNamingStrategy {

    public static final String DEFAULT_CLASS_TO_TABLE_PREFIX = "Grame";

    private String tablePrefix = DEFAULT_CLASS_TO_TABLE_PREFIX;

    public void setTablePrefix(String tablePrefix) {
        this.tablePrefix = tablePrefix;
    }

    @Override
    public String classToTableName(String className) {
        String simpleClassName = StringHelper.unqualify(className);
        if (tablePrefix == null || tablePrefix.isEmpty())
            return tableName(simpleClassName).toUpperCase();
        return tableName(tablePrefix + simpleClassName).toUpperCase();
    }
}